import {
	ROLE,
	BASE
} from '@/services/api'
import {
	request,
	METHOD
} from '@/utils/request'

/**
 * 所有角色
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function allRole() {
	return request(ROLE + "/allRole", METHOD.GET)
}

/**
 * 角色列表
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function list(params) {
	return request(ROLE + "/list", METHOD.GET, params)
}

export async function save(params) {
	return request(ROLE + "/save", METHOD.POST, params)
}

export async function update(params) {
	return request(ROLE + "/update", METHOD.POST, params)
}

export async function deleteOne(id) {
	let params = {
		roleId: id
	}
	return request(ROLE + "/deleteOne", METHOD.POST, params)
}
/**
 * 角色树
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function getTree() {
	let params = {}
	return request(BASE + "/menu/menuTree", METHOD.GET, params)
}
// 选中值
export async function selectTree(id) {
	let obj = {
		roleId: id
	}
	return request(BASE + "/roleMenu/getKey", METHOD.GET, obj)
}
// 添加权限
export async function addAuth(id, menuIdArr) {
	let obj = {
		roleId: id,
		menuIds: menuIdArr
	}
	return request(BASE + "/roleMenu/add", METHOD.POST, obj)
}
// 启用
export async function enable(id) {
	let obj = {
		roleId: id
	}
	return request(ROLE + "/enable", METHOD.POST, obj)
}
// 禁用
export async function disable(id) {
	let obj = {
		roleId: id
	}
	return request(ROLE + "/disable", METHOD.POST, obj)
}